// pages/channel/editMember/editMember.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    channel_promoter_id: '',
    userInfo: '',
    status: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      channel_promoter_id: options.channel_promoter_id
    })
    this.getInfo();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  // 状态开关
  switchChange(e) {
    this.setData({
      status: e.detail.value
    })
  },
  // 获取渠道推广员详情
  getInfo(){
    var that = this;
    app.ajax({
      url: 'User/Channel/getPromoterInfo',
      data: {
        channel_promoter_id: that.data.channel_promoter_id
      },
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            userInfo: res.data.data,
            status: res.data.data.status==1?true:false
          })
        }
      }
    })
  },
  // 提交
  submit() {
    var that = this;
    app.ajax({
      url: 'User/Channel/editPromoter',
      data: {
        channel_promoter_id: that.data.channel_promoter_id,
        telphone: that.data.userInfo.telphone,
        name: that.data.userInfo.name,
        account: that.data.userInfo.account,
        status: that.data.status?1:2
      },
      success: function (res) {
        if (res.data.code == 1000) {
          app.showToast('编辑成功', "none", 2000, function () { });
          wx.navigateBack();
        }else{
          app.showToast(res.data.message, "none", 2000, function () { });
        }
      }
    })
  },
})